package com.cabbagetofu.crowd.controller;


import com.atguigu.crowd.constant.CrowdConstant;
import com.atguigu.crowd.until.ResultEntity;
import com.cabbagetofu.api.MySQLRemoteService;
import com.cabbagetofu.crowd.entity.vo.PortalTypeVO;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class PortalController {

    @Autowired
    private MySQLRemoteService mySQLRemoteService;

    /**
     * 访问首页,从数据库中查询所有项目并展示
     * @return
     */
    @RequestMapping("/")
    public String showPortalPage(ModelMap modelMap){

        // 查询首页要显示的项目数据
        ResultEntity<List<PortalTypeVO>> typeProjectDataRemote = mySQLRemoteService.getPortalTypeProjectDataRemote();

        // 如果查询成功
        if(ResultEntity.SUCCESS.equals(typeProjectDataRemote.getResult())){

            // 将查询得到的数据放入ModelMap中
            List<PortalTypeVO> data = typeProjectDataRemote.getData();
            modelMap.addAttribute(CrowdConstant.ATTR_NAME_PORTAL_DATA, data);
        }

        return "portal";

    }

}
